<template>
  <!-- 头部导航栏 -->
  <div class="navBar">
    <div class="homeCon">
      <i class="fa fa-bars" aria-hidden="true" @click="showMenu"></i>
      <router-link class="navHome" to="/">
        <img class="avatar" :src="require('@/assets/logo.jpg')" alt="" />
        <div class="title">YuyuFeng</div>
      </router-link>
    </div>

    <div class="nav">
      <aLink
        class="navItem"
        v-for="(item, index) in navList"
        :key="index"
        :title="item.name"
        :path="item.path"
      />
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from "vue";
import link from "@/components/Link.vue";
import { sideBarRef } from "@/components/SideBar.vue";

interface Nav {
  name: string;
  path: string;
}

export default defineComponent({
  components: {
    aLink: link,
  },
  setup() {
    const navList = ref<Nav[]>([
      { name: "Me", path: "/me" },
      { name: "Echarts", path: "/echarts" },
      { name: "Css", path: "/css" },
      { name: "Openlayer", path: "/openlayer" },
    ]);

    const isMenuShow = ref(false);

    function showMenu() {
      if (isMenuShow.value) {
        sideBarRef.value.style.left = "-15rem";
      } else {
        sideBarRef.value.style.left = "0rem";
      }
      isMenuShow.value = !isMenuShow.value;
    }
    return { navList, showMenu };
  },
});
</script>

<style lang="scss" scoped>
.navBar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 999;
  height: 3rem;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #eaecef;
  background: #fff;
  padding: 0rem 2rem;
  .homeCon {
    display: flex;
    align-items: center;
  }
  .fa {
    display: none;
    color: #2c3e50;
    margin-right: 0.7rem;
    font-size: 1.8rem;
    cursor: pointer;
  }
  .navHome {
    display: flex;
    justify-self: start !important;
    justify-content: flex-start;
    align-items: center;
    .avatar {
      height: 2.2rem;
      width: 2.2rem;
      margin-right: 1rem;
    }
    .title {
      font-size: 1rem;
      color: #2c3e50;
      font-weight: 500;
    }
  }
  .nav {
    height: 100%;
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-around;
  }
  @media screen and (max-width: 790px) {
    .title {
      display: none;
    }
    .fa {
      display: inline-block;
    }
  }
}
</style>
